#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/*
 * main() is the starting point for all C and C++ programs.
 */
int main()
{
	// declarations for the input and output file pointers
	FILE* input;
	FILE* output;

	// put your program's variable declarations here
	int* firstArray;
	int* secondArray;
	int* thirdArray;
	unsigned int lengthOfArrays;

	//Generic iteration index
	int i;
	
	//The current value being read in from the file
	int currentValue;

	//The final dot product result
	int finalResult = 0;

	// opening the input and output files
	input = fopen("input.txt", "r");
	output = fopen("output.txt", "w");

	// use the following two lines as examples of how to read from and write to files)
	// fscanf(input, "%d", &x); // reads a number from the input file into the variable x
	// fprintf(output, "The number %d was read in\n", x);  // writes a number from the variable x into the output file


	// start your program code here

	//Reading in the size of the arrays
	fscanf(input, "%d\n", &lengthOfArrays);

	//Allocating memory
	firstArray = (int*)malloc(lengthOfArrays * sizeof(int));
	secondArray = (int*)malloc(lengthOfArrays * sizeof(int));
	thirdArray = (int*)malloc(lengthOfArrays * sizeof(int));

	//Reading in the first set of numbers and storing them
	for(i = 0; i < lengthOfArrays; i++)
	{
		fscanf(input, "%d\n", &currentValue);
		firstArray[i] = currentValue;
	}

	//Reading in the second set of numbers and storing them
	for(i = 0; i < lengthOfArrays; i++)
	{
		fscanf(input, "%d\n", &currentValue);
		secondArray[i] = currentValue;
	}

	//Calculating the dot product (first step)
	for(i = 0; i < lengthOfArrays; i++)
	{
		thirdArray[i] = firstArray[i] * secondArray[i];
	}

	//Calculating the dot product (first step)
	for(i = 0; i < lengthOfArrays; i++)
	{
		finalResult = finalResult + thirdArray[i];
	}

	//Writing the final result to the file output.txt
	fprintf(output, "%d", finalResult);

	//Freeing allocated memory
	free(firstArray);
	free(secondArray);
	free(thirdArray);

	// closing the input and output files
	fclose(input);
	fclose(output);

	// main() must return a value; zero means the program ended without error.
	return 0;
}